<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>数据源编辑</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/libs/layui2.2.5/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="icon" href="${pageContext.request.contextPath}/static/libs/uiframe/frame/static/image/code.png">
    <style type="text/css">
        .layui-input-block {
            margin-left: 130px;
            min-height: 36px;
        }

        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 100px;
            font-weight: 400;
            text-align: right;
        }
    </style>

    <script type="text/javascript" src="${pageContext.request.contextPath}/static/libs/layui2.2.5/layui.js"></script>
    <script>
       var sourceId = '${source.sourceId}',type = '${type}';

        layui.use(['form', 'layer'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            //自定义验证规则
            form.verify({
                number: function (value) {
//                    if(/^\d+\d+\d$/.test(value)){
//                        return '输入项必须为数字';
//                    }
                },

                sourceName: function (value) {
                    if (value.length < 2) {
                        return '应用名称至少得2个字符';
                    }
                },
                description: function (value) {
//                    if(value.length < 2){
//                        return '描述至少得2个字符啊';
//                    }
                }
            });

            form.on('select(type)', function(data){
                var hight,selectType = data.value;
                if(selectType == 'ol.source.Vector'){
                    hight = '350px';
                }else if(selectType == 'ol.supermap.SpatialAnalystService'){
                    hight = '300px';
                }else {
                    hight = '550px';
                }
                parent.layer.iframeSrc(parent.layIndex, '${pageContext.request.contextPath}/ol/sourceadd?type=' + selectType);
                parent.layer.style(parent.layIndex, {height:hight});
            });

            //监听提交
            form.on('submit(sourceadd)', function (data) {
                var formData = data.field, url, optionsData = {};
                if (sourceId == "") {
                    url = '${pageContext.request.contextPath}/ol/sourcecreate';
                } else {
                    url = '${pageContext.request.contextPath}/ol/sourceedit';
                }
                if(formData['type'] != null && formData['type'] != ""){
                    type = formData['type'];
                }


                if (formData['url'] != null && formData['url'] != "") {
                    optionsData['url'] = formData['url'];
                }
                if (formData['wrapX'] != null && formData['wrapX'] != "") {
                    optionsData['wrapX'] = formData['wrapX'];
                }
                if (formData['opaque'] != null && formData['opaque'] != "") {
                    optionsData['opaque'] = formData['opaque'];
                }
                if (formData['cacheSize'] != null && formData['cacheSize'] != "") {
                    optionsData['cacheSize'] = formData['cacheSize'];
                }
                if (formData['tileLoadFunction'] != null && formData['tileLoadFunction'] != "") {
                    optionsData['tileLoadFunction'] = formData['tileLoadFunction'];
                }
                if (formData['layer'] != null && formData['layer'] != "") {
                    optionsData['layer'] = formData['layer'];
                }
                if (formData['format'] != null && formData['format'] != "") {
                    optionsData['format'] = formData['format'];
                }
                if (formData['matrixSet'] != null && formData['matrixSet'] != "") {
                    optionsData['matrixSet'] = formData['matrixSet'];
                }
                if (formData['style'] != null && formData['style'] != "") {
                    optionsData['style'] = formData['style'];
                }
                if (formData['datasource'] != null && formData['datasource'] != "") {
                    optionsData['datasource'] = formData['datasource'];
                }
                if (formData['dataset'] != null && formData['dataset'] != "") {
                    optionsData['dataset'] = formData['dataset'];
                }
                if (formData['attributeFilter'] != null && formData['attributeFilter'] != "") {
                    optionsData['attributeFilter'] = formData['attributeFilter'];
                }
                if (formData['geometry'] != null && formData['geometry'] != "") {
                    optionsData['geometry'] = formData['geometry'];
                }


                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: url,
                    data: {
                        sourceId: sourceId,
                        sourceName: formData['sourceName'],
                        projection:formData['projection'],
                        type: type,
                        options: optionsData,
                        description: formData['description']
                    },
                    success: function (data) {
                        layer.msg(data.status);
                        window.parent.layIndex = null;
                        window.parent.closeAllLayer();
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
                return false;
            });
        })
    </script>
</head>
<body>
<form class="layui-form c3form" action="">
    <c:choose>
        <c:when test="${type == 'ol.source.TileSuperMapRest'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest" selected="selected">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">水平方向重复：</label>
                <div class="layui-input-block">
                    <c:choose>
                        <c:when test="${source.options.wrapX == 'true'}">
                            <input type="radio" name="wrapX" value="true" title="是">
                            <input type="radio" name="wrapX" value="false" title="否" checked="checked">
                        </c:when>
                        <c:when test="${source.options.wrapX == 'false'}">
                            <input type="radio" name="wrapX" value="true" title="是" checked="checked">
                            <input type="radio" name="wrapX" value="false" title="否">
                        </c:when>
                        <c:otherwise>
                            <input type="radio" name="wrapX" value="true" title="是" checked="checked">
                            <input type="radio" name="wrapX" value="false" title="否">
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">切片透明：</label>
                <div class="layui-input-block">
                    <c:choose>
                        <c:when test="${source.options.opaque == 'true'}">
                            <input type="radio" name="opaque" value="true" title="是" checked="checked">
                            <input type="radio" name="opaque" value="false" title="否">
                        </c:when>
                        <c:when test="${source.options.opaque == 'false'}">
                            <input type="radio" name="opaque" value="true" title="是">
                            <input type="radio" name="opaque" value="false" title="否" checked="checked">
                        </c:when>
                        <c:otherwise>
                            <input type="radio" name="opaque" value="true" title="是">
                            <input type="radio" name="opaque" value="false" title="否" checked="checked">
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">缓冲大小：</label>
                <div class="layui-input-block">
                    <input type="text" name="cacheSize" value="${source.options.cacheSize}"
                           lay-verify="number" placeholder="请输入缓冲大小" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">切片回调函数：</label>
                <div class="layui-input-block">
                    <input type="text" name="tileLoadFunction" value="${source.options.tileLoadFunction}"
                           placeholder="请输入切片加载完成后的执行函数" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述：</label>
                <div class="layui-input-block">
                        <textarea name="description" value="${source.description}"
                                  placeholder="请输入描述内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'ol.source.TileArcGISRest'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest" selected="selected">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.options.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述：</label>
                <div class="layui-input-block">
                        <textarea name="description" value="${source.description}"
                                  placeholder="请输入描述内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'ol.source.WMTS'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS" selected="selected">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">layer：</label>
                <div class="layui-input-block">
                    <input type="text" name="layer" value="${source.options.layer}"
                           lay-verify="" autocomplete="off" placeholder="请输入layer" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">format：</label>
                <div class="layui-input-block">
                    <input type="text" name="format" value="${source.options.format}"
                           lay-verify="" autocomplete="off" placeholder="请输入format" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">matrixSet：</label>
                <div class="layui-input-block">
                    <input type="text" name="matrixSet" value="${source.options.matrixSet}"
                           lay-verify="" autocomplete="off" placeholder="请输入matrixSet" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">style：</label>
                <div class="layui-input-block">
                    <input type="text" name="style" value="${source.options.style}"
                           lay-verify="" autocomplete="off" placeholder="请输入style" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述：</label>
                <div class="layui-input-block">
                        <textarea name="description" value="${source.description}"
                                  placeholder="请输入描述内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'ol.source.Vector'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector" selected="selected">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'ol.supermap.FeatureService'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService" selected="selected">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源：</label>
                <div class="layui-input-block">
                    <input type="text" name="datasource" value="${source.options.datasource}"
                           lay-verify="" autocomplete="off" placeholder="请输入数据源（datasource）" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据集：</label>
                <div class="layui-input-block">
                    <input type="text" name="dataset" value="${source.options.dataset}"
                           lay-verify="" autocomplete="off" placeholder="请输入数据集（dataset）" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">属性过滤条件：</label>
                <div class="layui-input-block">
                    <input type="text" name="attributeFilter" value="${source.options.attributeFilter}"
                           lay-verify="" autocomplete="off" placeholder="请输入属性过滤条件" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">几何过滤条件：</label>
                <div class="layui-input-block">
                    <input type="text" name="geometry" value="${source.options.geometry}"
                           lay-verify="" autocomplete="off" placeholder="请输入几何过滤条件" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'arcgis.FeatureService'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService" selected="selected">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">投影类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="projection" value="${source.projection}"
                           lay-verify="" placeholder="请输入投影类型，如：EPSG:4326" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:when test="${type == 'ol.supermap.SpatialAnalystService'}">
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type" disabled="disabled">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService" selected="selected">超图分析服务</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="sourceName" value="${source.sourceName}"
                           lay-verify="sourceName" autocomplete="off" placeholder="请输入数据源名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">服务地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="url" value="${source.options.url}"
                           lay-verify="" autocomplete="off" placeholder="请输入服务地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sourceadd">提 交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
                </div>
            </div>
        </c:when>
        <c:otherwise>
            <div class="layui-form-item">
                <label class="layui-form-label">数据源类型：</label>
                <div class="layui-input-block">
                    <select name="type" lay-filter="type">
                        <option value="">请选择数据源类型</option>
                        <option value="ol.source.TileSuperMapRest">超图切图服务</option>
                        <option value="ol.source.TileArcGISRest">ArcGIS切图服务</option>
                        <option value="ol.source.WMTS">WMTS服务</option>
                        <option value="ol.source.Vector">矢量数据</option>
                        <option value="ol.supermap.FeatureService">超图数据服务</option>
                        <option value="arcgis.FeatureService">arcgis数据服务</option>
                        <option value="ol.supermap.SpatialAnalystService">超图分析服务</option>
                    </select>
                </div>
            </div>
        </c:otherwise>
    </c:choose>
</form>
</body>
</html>
